export const base_url = 'http://10.2.1.23:8080'; // 根据实际环境调整
const timeout = 5000;

const request = (params) => {
  const url = base_url + params.url; // 正确拼接 URL
  const method = params.method || "get";
  const data = params.data || {};
  const Token = uni.getStorageSync("userInfo").token;


  return new Promise((resolve, reject) => {
    uni.request({
      url: url,
      method: method,
	  header: {
		  "token":Token
	  },
      data: data,
      timeout,
	  
      success(response) {
        if (response.statusCode === 200) {
          resolve(response.data);
        } else {
          reject(new Error('请求失败'));
        }
      },
      fail(err) {
        reject(err);
      }
    });
  });
};

export default request;